package com
{
	import com.*;
	import com.Engine.*;
	import com.Home.*;
	import com.Packet.*;
	import com.UI.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.external.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.net.*;
	import flash.system.*;
	import flash.utils.*;
	import flash.utils.Timer;
	
	import gs.*;
	import gs.easing.*;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	import org.aswing.plaf.*;
	import org.aswing.plaf.basic.frame.BasicFrameTitleBarBG;
	import org.aswing.skinbuilder.SkinProgressBarBackground;
	import org.aswing.skinbuilder.SkinProgressBarForeground;
	
	public class FrameFullScreenEffect  extends JFrame
	{
		public function FrameFullScreenEffect()
		{
			super();
			setDragable(false);
			setClosable(false);
			setResizable(false);
			setTitleBar(null);
			setBorder(new EmptyBorder());
			setBackgroundDecorator(new SolidBackground(new ASColor(0,0)));
			
			//component creation
			setSize(new IntDimension(1200, 600));
			setPreferredSize(new IntDimension(1200, 600));
			var layout0:EmptyLayout = new EmptyLayout();
			getContentPane().setLayout(layout0);
			
			this.setEnabled(false);
			getContentPane().setEnabled(false);
		}
		
		public function renderEffects():void
		{
			PanelMainHelp.getInstance().bringToTop(_frame);
			
			var removeArray:Array = [];
			var count:int = 0;
			var k:int = 0;
			var mc_tmp:MovieClip = null;
			for each(var obj:Object in _effects)
			{
				obj.frame++;
				if((obj.mc as MovieClip).totalFrames == 1)
				{
					count = (obj.mc as MovieClip).numChildren;
					for(k = 0; k < count; k++)
					{
						mc_tmp = (obj.mc as MovieClip).getChildAt(k) as MovieClip;
						if(mc_tmp != null)
						{
							if(obj.frame > mc_tmp.totalFrames)
							{
								obj.frame = 1;
								if(obj.remove_at_end)
								{
									removeArray.push(obj.effect_id);
								}
							}
							mc_tmp.gotoAndStop(obj.frame);
						}
					}
				}
				else
				{
					if(obj.frame > (obj.mc as MovieClip).totalFrames)
					{
						obj.frame = 1;
						if(obj.remove_at_end)
						{
							removeArray.push(obj);
						}
					}
					
					count = (obj.mc as MovieClip).numChildren;
					for(k = 0; k < count; k++)
					{
						mc_tmp = (obj.mc as MovieClip).getChildAt(k) as MovieClip;
						if(mc_tmp != null)
						{
							mc_tmp.gotoAndStop(obj.frame % mc_tmp.totalFrames + 1);
						}
					}
					
					(obj.mc as MovieClip).gotoAndStop(obj.frame);
				}
			}
			
			for each(var item:Object in removeArray)
			{
				if(item.callback_remove != null)
					(item.callback_remove as Function).apply();
				removeEffect(item.effect_id);
			}
		}
		private var _effects:Object = new Object();
		public function addEffect(id:int,mc_effect:MovieClip,bRemoveAtEnd:Boolean = true,callbackRemove:Function = null):void
		{
			
			if(_effects[id] != null)
			{
				if(mc_effect != null)
				{
					mc_effect.stop();
					mc_effect = null;
				}
				return;
			}
			
			_effects[id] = {effect_id:id,mc:mc_effect,frame:1,remove_at_end:bRemoveAtEnd,callback_remove:callbackRemove};
			if(mc_effect == null)
				return;
			if(contains(_effects[id].mc))
				return;

			mc_effect.gotoAndStop(_effects[id].frame);
			addChild(mc_effect);
		}
		
		public function removeEffect(id:int):void
		{
			if(_effects[id] == null)
				return;
			if(contains(_effects[id].mc))
			{
				(_effects[id].mc as MovieClip).stop();
				removeChild(_effects[id].mc);
			}
			_effects[id] = null;
			delete _effects[id];
			Engine.gc();
		}
		public function hasEffect(id:int):Boolean
		{
			if(_effects[id] == null)
				return false;
			if(contains(_effects[id].mc))
				return true;
			return false;
		}
		
		public static var _frame:FrameFullScreenEffect = null;
		public static function show():void
		{
			if(_frame == null)
			{
				_frame = new FrameFullScreenEffect();
				PanelMainHelp.getInstance().addChild(_frame);
			}
			_frame.show();
			PanelMainHelp.getInstance().bringToTop(_frame);
			
		}
		public static function hide():void
		{
			if(isShowing())_frame.hide();
		}
		public static function isShowing():Boolean
		{
			return(_frame != null&& _frame.isShowing());
		}
	}
}